package com.wlyy.his.infrastructure.helper;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;

/**
 * @author 10097
 */
public class HisDemoSdk {
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DefaultHttpClient httpclient = new DefaultHttpClient();

        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());

        FileInputStream keyStoreIn = new FileInputStream(new File(
                "com/ssl/http/clientKeystore.jks"));
        FileInputStream trustStoreIn = new FileInputStream(new File(
                "com/ssl/http/clientTruststore.jks"));

        try {
            keyStore.load(keyStoreIn, "123456".toCharArray());
            trustStore.load(trustStoreIn, "123456".toCharArray());
        } finally {
            keyStoreIn.close();
            trustStoreIn.close();
        }

        SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore,
                "123456", trustStore);
        Scheme sch = new Scheme("https", socketFactory, 8443);

        httpclient.getConnectionManager().getSchemeRegistry().register(sch);


        HttpPost httpPost = new HttpPost("https://183.129.242.245:19081/appserver-restful/requestMessage");


        HttpGet httpget = new HttpGet("https://w03gca01a:8443/");

        System.out.println("Request:" + httpget.getRequestLine());

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: "
                    + entity.getContentLength());
        }
        if (entity != null) {
            entity.consumeContent();
        }
        httpclient.getConnectionManager().shutdown();

    }

}
